
import java.io.*;
import java.net.*;
/**
 * Description:
 * ???: <a href="http://www.crazyit.org">???Java????</a><br>
 * Copyright (C), 2001-2018, Yeeku.H.Lee<br>
 * This program is protected by copyright laws.<br>
 * Program Name:<br>
 * Date:<br>
 * @author Yeeku.H.Lee kongyeeku@163.com
 * @version 1.0
 */
// ??????????????
public class ServerThread implements Runnable
{
	//
	Socket s = null;
	// ????????????Socket?????????????
	BufferedReader br = null;
	public ServerThread(Socket s)
	throws IOException
	{
		this.s = s;
		// ???????Socket???????????
		br = new BufferedReader(new InputStreamReader(s.getInputStream()));
	}
	public void run()
	{
		try
		{
			String content = null;
			// ????????????Socket?????????????????????
			while ((content = readFromClient()) != null)
			{
				// ????socketList??????Socket??
				// ?????????????????Socket???????
				for (Socket s : MyServer.socketList)
				{
					PrintStream ps = new PrintStream(s.getOutputStream());
					ps.println(content);
				}
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	// ???????????????????
	private String readFromClient()
	{
		try
		{
			return br.readLine();
		}
		// ??????????????????Socket???????????????
		catch (IOException e)
		{
			// ?????Socket??
			MyServer.socketList.remove(s);      // ??
		}
		return null;
	}
}
